package com.douziit.meilianoa.base.constant;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

/**
 * Created by dev31 on 2018/9/29.
 */
@Configuration
public class FileUploadConfig {

    /**
     * 文件上传配置
     *
     *  @return MultipartConfigElement
     */
    @Bean
    public MultipartConfigElement multipartConfigElement(@Value("${multipart.maxFileSize}") DataSize maxFileSize,
                                                         @Value("${multipart.maxRequestSize}") DataSize maxRequestSize) {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        // 单个文件最大
        factory.setMaxFileSize(maxFileSize);
        // 设置总上传数据总大小
        factory.setMaxRequestSize(maxRequestSize);
        return factory.createMultipartConfig();
    }

}
